package com.atguigu.demo.customer.controller;

import com.atguigu.demo.customer.bean.Customer;
import com.atguigu.demo.customer.service.CustomerService;
import com.atguigu.demo.customer.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService  ;  //1 创建一个对象  //2 装配对象给引用

    @RequestMapping("/sayHello")
    public String  sayHello(){
        return "hello world ";
    }

    @GetMapping("detail")
    public String detail(@RequestParam(value = "name",required = false) String name){
        return "customer name:"+name ;
    }

    @GetMapping("/detail/{id}")
    public String detailById(@PathVariable("id") Long  id){

        Customer customer = customerService.getCustomerById(id);
        return  "customer id :"+ customer ;
    }

    @PostMapping("/detail")
    public String saveCustomer(@RequestBody Customer customer ){
        customerService.saveCustomer(customer);

        return "customer name:"+customer.getName()+" age:"+customer.getAge();
    }
}
